package com.darthsith.droidathome.core.service.impl;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.darthsith.droidathome.core.component.Worker;
import com.darthsith.droidathome.core.dao.ArduinoBoardDao;
import com.darthsith.droidathome.core.model.ArduinoBoard;
import com.darthsith.droidathome.core.service.ScheduledService;

@Service
public class ScheduledServiceImpl implements ScheduledService {
	
	private static final Log logger=LogFactory.getLog(ScheduledServiceImpl.class);
	
	private AtomicInteger atomicInteger=new AtomicInteger();
	
	@Autowired
	private Worker worker;
	@Autowired
	private ArduinoBoardDao arduinoBoardDao;

	@Scheduled(fixedRate=60000)
	public void doJob() {
		logger.info("DO JOB EVERY MINUTE");
		worker.work(atomicInteger.incrementAndGet());
	}

//	@Scheduled(cron="")
	@Override
	public List<ArduinoBoard> getSystemStatus() {
		return arduinoBoardDao.listAll();
	}
}
